﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.EarTag.API.Application.MediatorCommand.ProductionGradingCommand;
using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;

namespace S.EarTag.API.Controllers
{
    /// <summary>
    /// 生产定级写——控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionGradingController : BaseController
    {
        private readonly IMediator _mediator;
        public ProductionGradingController(IMediator mediator,MySqlDbContext _db):base(_db)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 修改生产定级信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdProductionGrading(ProductionGradingUpdateCommand command)
        {
            command.UpdateBy = UserStrategyDto.UserTrueName;
            command.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            command.CreateBy = UserStrategyDto.UserTrueName;
            command.CreateDate = DateTime.Now;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 批量删除生产定级信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> BatchRemoveProductionGrading(ProductionGradingBatchRemoveCommand command)
        {
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据主键di单删生产定级信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> RemoveProductionGrading(int id)
        {
            ProductionGradingRemoveCommand command = new ProductionGradingRemoveCommand();
            command.ProductionGradingId = id;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 添加生产定级信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddProductionGrading(ProductionGradingCreateCommand command)
        {
            command.CreateBy = UserStrategyDto.UserTrueName;
            command.CreateDate = DateTime.Now;
            command.UpdateBy = "";
            command.UpdateDate = "";
            var result=await _mediator.Send(command);
            return Ok(result);
        }
    }
}
